package com.wolfalpha.lwtool.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 数据库
 * 
 * @author ttStudio
 * 
 */
public class DBHelper extends SQLiteOpenHelper {

	private final static String DATABASE_NAME = "todo_db";
	private final static int DATABASE_VERSION = 1;
	public final static String JOBTABLE_NAME = "job_table";
	public final static String FIELD_JID = "job_id";
	public final static String FIELD_JTITLE = "job_title";
	public final static String FIELD_JTIME = "job_time";
	public final static String FIELD_JDATE = "job_date";

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	public void onCreate(SQLiteDatabase db) {
		StringBuffer sBuffer = new StringBuffer();
        sBuffer.append("CREATE TABLE [" + JOBTABLE_NAME + "] (");
        sBuffer.append("[job_id] INTEGER NOT NULL PRIMARY KEY, ");
        sBuffer.append("[job_title] TEXT,");
        sBuffer.append("[job_date] TEXT,");
        sBuffer.append("[job_time] TEXT)");
		db.execSQL(sBuffer.toString());
	}

	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		String sql = "DROP TABLE IF EXISTS " + JOBTABLE_NAME;
		db.execSQL(sql);
		onCreate(db);
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
		// 每次打开数据库之后首先被执行
		Log.d("Open", "DatabaseHelper onOpen");
	}
}
